﻿CREATE PROCEDURE [dbo].[TempPIDifferences_UpdateIds]
	@RangeReviewId int
AS
	--ArticleIds
	Update TempPIDifferences
	Set ArticleId = case when a.Id is not null then a.Id else 0 end
	From TempPIDifferences t
	LEFT JOIN Articles a on t.ArticleCode = a.Code and a.RangeReviewId = @RangeReviewId

	--StoreIds
	Update TempPIDifferences
	Set StoreId = case when s.Id is not null then s.Id else 0 end
	From TempPIDifferences t
	LEFT JOIN Stores s on t.StoreCode = s.Code and s.CountryId = (Select CountryId From RangeReviews Where Id = @RangeReviewId)